import { defineStore } from 'pinia'
import { privateRoutes } from '@/router'
import router from '@/router'
import store from '../index'
import { ref } from 'vue'
export const usePermissionStore = defineStore('permissionStore', () => {
  const routes = ref([])
  const hasRoute = ref(false)
  const setRoutes = (menus) => {
    menus.forEach((menu) =>
      routes.value.push(privateRoutes.find((privateRoute) => privateRoute.name === menu))
    )
    routes.value.forEach((route) => router.addRoute(route))
    hasRoute.value = true
  }
  const removeRoutes = () => {
    routes.value.forEach((route) => router.removeRoute(route.name))
    hasRoute.value = false
  }
  return { routes, hasRoute, setRoutes, removeRoutes }
})
